Skip to content

fix: correct ILIAS scraping and session handling bugs - #3

Merged
DenizAltunkapan merged 2 commits into
mainfrom
fix/ilias-scraping-and-session-bugs
Aug 30, 2026
Merged

DenizAltunkapan merged 2 commits into
mainfrom
fix/ilias-scraping-and-session-bugs

Conversation

@Atrapfare

@Atrapfare Atrapfare commented Aug 11, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

The exercise tooling was largely non-functional against real courses, and a
few repository/session bugs caused silently wrong results rather than errors.
Verified against a live ILIAS instance (Uni Stuttgart, SS26 courses).

Exercise tooling

Bug Effect
_overview_url omitted mode=all list_exercise_assignments returned count: 0 for every past or upcoming assignment — ILIAS only renders running ones by default
Submission/upload/team URLs read from ilAssignmentPresentationGUI That page redirects to the overview without the dynamic cmdNode those links carry → HTTP 500 on list_submitted_files, uploads and team screens
Deadline regex expected 04.05.2026 ILIAS writes 4. Mai 2026, 08:00 and mixes full with abbreviated month names → deadline always empty
"abgegeben" tested before "nicht abgegeben" An unsubmitted sheet was reported as submitted (substring collision)
remove_team_member posted only cmd[confirmRemoveTeamMember] The confirmation screen was never answered, so nobody was ever removed — yet it reported success
Write ops returned status: "ok" unconditionally ILIAS answers an ignored POST with HTTP 200; callers could not tell. They now diff before/after and report "unchanged"
search_users did not encode term Names with spaces or umlauts broke the query
rtoken read only from the form action CSRF token empty when ILIAS puts it in a hidden field
Three regex-extracted URLs skipped unescape() Inconsistent with the fourth; & leaked into URLs

Repository handling

  • _detect_file_url() accepted a ref_id parameter and ignored it. A container
    page also lists its children's download links, so download_file(<folder>)
    and get_file_content(<folder>) silently returned the first file inside
    the folder. Containers now raise instead.
  • Uploaded .html files could never be downloaded — the guard rejected every
    text/html response as an ILIAS error page. Real downloads always carry a
    Content-Disposition filename; UI and error pages never do.
  • Exercise objects were bucketed as the generic "item" type despite driving
    the submission tools; they now crawl as "exercise".

Session handling

  • AuthService._logged_in was a one-way latch, so an expired ILIAS session was
    never renewed and every later call silently parsed the login page. All five
    services now fetch through AuthService.get(), which detects the login page
    and re-authenticates once.
  • POST transport errors escaped several tools unhandled (ExerciseService had a
    _get wrapper but posted raw); added the matching _post.
  • An unparsable seed made list_calendar_events silently return today's
    events instead of erroring.

Verification

  • ruff check / ruff format --check / pytest / python -m build all pass.
    The 9 ruff violations were pre-existing and are fixed here, so CI goes green.
  • Test suite grown from 10 to 31 cases, including regression tests for the
    folder-vs-file resolution, the German date formats, the status substring
    collision, the login-page detection and the confirmation-screen handling.
  • Live smoke test against ILIAS: 20/20 read-only tool calls pass.

Not verified

The four mutating tools — submit_exercise_file, delete_submitted_files,
add_team_member, remove_team_member — were not executed against the live
server, since doing so would alter real submissions and teams. Their fixes are
derived from the observed HTML and covered by unit tests, but are unconfirmed
end-to-end. Worth a careful manual check on a throwaway assignment.

Dependency pin

mcp 2.0.0 removed create_connected_server_and_client_session from
mcp.shared.memory, which tests/test_mcp_server.py imports. Since the
constraint was an open mcp>=1.9.0, a fresh CI install resolved to 2.0.0 and
failed collection — unrelated to the changes here, and it would hit main on
its next run too. Pinned to <2.0.0; migrating to the 2.x interface is a
separate piece of work.

🤖 Generated with Claude Code

Exercise tooling was largely non-functional against real courses:

- list_exercise_assignments returned nothing for past or upcoming
  assignments. The overview URL omitted mode=all, and ILIAS only renders
  currently running assignments by default.
- list_submitted_files, the upload form and the team screen resolved
  their URLs from ilAssignmentPresentationGUI, which redirects to the
  overview without the dynamic cmdNode those links need, producing a
  HTTP 500. They now read the overview page instead.
- Deadlines were never parsed: ILIAS writes "4. Mai 2026, 08:00" and
  mixes full with abbreviated month names, not "04.05.2026".
- Status could report "abgegeben" for a row saying "nicht abgegeben",
  because the positive substring was tested first.
- remove_team_member only posted the confirmation step, so it never
  removed anybody while still reporting success.
- Team and delete operations reported status "ok" even when ILIAS
  ignored the request; they now verify the change and report
  "unchanged" otherwise.
- search_users did not URL-encode the search term.
- rtoken was only read from the form action, never from the hidden
  field, leaving the CSRF token empty on some forms.
- Three regex-extracted URLs skipped unescape() unlike the fourth.

Repository handling:

- download_file and get_file_content on a folder silently returned the
  first file contained in it, because _detect_file_url ignored the
  ref_id it was given. Containers now raise instead.
- Uploaded .html files could never be downloaded: the guard rejected
  every text/html response as an ILIAS error page. Real downloads always
  carry a Content-Disposition filename, error pages never do.
- Exercise objects were typed as the generic "item".

Session handling:

- An expired ILIAS session was never renewed. _logged_in was a one-way
  latch, so every later call silently parsed the login page. Requests
  now go through AuthService.get(), which re-authenticates once.
- POST transport errors escaped several tools unhandled.
- An unparsable calendar seed silently returned events for today.

Also fixes the pre-existing ruff violations so CI passes, and grows the
test suite from 10 to 31 cases.
Copilot AI lite review requested due to automatic review settings August 11, 2026 16:29
mcp 2.0.0 removed create_connected_server_and_client_session from
mcp.shared.memory, which tests/test_mcp_server.py imports, so a fresh
install resolved to 2.0.0 and broke collection. Earlier CI runs were
green only because they predate the 2.0.0 release.

Pinning keeps the currently supported API; migrating to the 2.x
interface is a separate change.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes multiple real-world ILIAS scraping, repository download, and session-expiry handling issues that previously caused silent misbehavior (wrong/empty results) rather than surfaced errors, and expands unit/regression coverage around those behaviors.

Changes:

  • Add AuthService.get() with login-page detection + one-time re-authentication, and route several services’ GETs through it.
  • Fix repository file-vs-container resolution and improve file-download detection (including allowing real uploaded .html downloads via Content-Disposition).
  • Improve exercise tooling parsing and flows (German deadline formats, status substring collision, URL unescaping/selection, team-member confirmation flow) and add regression tests.

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/test_repository_service.py Adds regression tests for folder-vs-file download URL detection and Content-Disposition-based HTML download handling.
tests/test_exercise_service.py Adds regression tests for confirmation-screen handling, deadline parsing, status parsing order, rtoken extraction, and URL unescaping.
tests/test_auth_service.py Adds tests for login-page detection on expired sessions and avoiding false positives on binary responses.
src/services/repository_service.py Prevents containers from being treated as files, tightens download URL detection, improves download HTML-page detection, and routes GET/downloads via AuthService.get().
src/services/news_service.py Routes dashboard news fetch through AuthService.get().
src/services/exercise_service.py Fixes multiple parsing/URL/CSRF/team-confirmation issues; introduces a _post helper but currently lacks login-page detection on POST.
src/services/course_service.py Routes memberships fetch through AuthService.get().
src/services/calendar_service.py Routes calendar fetch through AuthService.get().
src/services/auth_service.py Adds relogin() and get() with login-page detection and one retry.
src/services/init.py Reorders exports.
src/mcp_app/server.py Validates calendar seed format to avoid silently returning the wrong day; uses local date when seed is empty.
src/core/config.py Import-order adjustment.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +595 to +599
def _post(self, url: str, label: str, **kwargs: object) -> requests.Response:
"""POST relative to the ILIAS base URL, surfacing transport errors."""
kwargs.setdefault("timeout", self.settings.timeout_seconds)
kwargs.setdefault("allow_redirects", True)
try:
@DenizAltunkapan
DenizAltunkapan merged commit 9cf4ab3 into main Aug 30, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants